package com.sky.controller.admin;

import com.sky.constant.RedisKeyConstant;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.OverridesAttribute;
import java.util.List;


/**
 * @PROJECT_NAME:sky-take-out
 * @NAME: ShopController
 * @AUTHOR:$$
 * @Date:2023-08-15
 * @DESCRIPTION:
 **/

/**
 * 店铺控制器
 *
 * @author t3rik
 */
@RestController("adminShopController")
@RequestMapping("admin/shop")
@Api(tags ="店铺相关接口")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置营业状态
     * 1 营业中
     * 0 打烊
     *
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status){
        //保存到redis中
        //k-v
        //设置当前店铺的营业厅状态
       this.redisTemplate.opsForValue().set(RedisKeyConstant.SHOP_STATUS_KEY,status);
        return Result.success();
    }
    /**
     * 查看营业状态
     *
     */
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        //直接从redis中取状态
           Integer status  =(Integer) this.redisTemplate.opsForValue().get(RedisKeyConstant.SHOP_STATUS_KEY);
        return Result.success(status);
    }
}
